export default defineEventHandler(async (event) => {
  const body = await readBody(event);

  // 模拟保存能力实例
  const capabilityInstance = {
    id: body.id || `instance_${Date.now()}`,
    resourceId: body.resourceId,
    capabilityId: body.capabilityId,
    name: body.name,
    status: body.status || 'enabled',
    configuration: body.configuration || {},
    state: {
      isAvailable: true,
      lastCheckTime: Date.now(),
      performance: {
        responseTime: 0,
        throughput: 0,
        successRate: 100,
      },
    },
    metrics: {
      totalCalls: 0,
      successCalls: 0,
      failedCalls: 0,
      averageResponseTime: 0,
      lastCallTime: null,
    },
    logs: [],
    createTime: Date.now(),
    updateTime: Date.now(),
  };

  // 这里应该保存到数据库
  console.log('保存能力实例:', capabilityInstance);

  return {
    code: 0,
    data: capabilityInstance,
    message: '保存成功',
  };
});
